package cn.antia.cep.test;

import java.sql.*;

public class DataTransfer {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		new DataTransfer().addExp(56, "Rsrr8412", 70);
	}
	
	public void addExp(int fsid,String fsname,int atosid){
		try{
			String url = "jdbc:mysql://userdb.east.net.cn:3306/2collegeboard_co";
			String user = "2collegeboard_co";
			String pass = "jiahuayingdong";
			Class.forName("org.gjt.mm.mysql.Driver").newInstance();
			Connection connection = DriverManager.getConnection(url, user, pass);
			Statement statement = connection.createStatement();
			String insertSql = "insert into section_question(id,section_id,section_code,test_id,test_type,comment) values (null," + atosid + ",'" + fsname + "',?,?,'diy add')";
			PreparedStatement preparedStatement = connection.prepareStatement(insertSql);
			String sql = "select test_id,test_type from section_question where section_id = " + fsid;
			ResultSet set = statement.executeQuery(sql);
			int n = 0;
			while(set.next()){
				int testId = set.getInt("test_id");
				int testType = set.getInt("test_type");
				preparedStatement.setInt(1, testId);
				preparedStatement.setInt(2, testType);
				int i = preparedStatement.executeUpdate();
				System.out.println("update " + i + " record.Times:" + ++n);
			}
		}catch(Exception e){
			e.printStackTrace();
		}
		
	}
	
	public void transfer(){
		try{
			String url = "jdbc:mysql://userdb.east.net.cn:3306/2collegeboard_co";
			String user = "2collegeboard_co";
			String pass = "jiahuayingdong";
			Class.forName("org.gjt.mm.mysql.Driver").newInstance();
			Connection connection = DriverManager.getConnection(url, user, pass);
			Statement statement = connection.createStatement();
			PreparedStatement preparedStatement = connection.prepareStatement("update genus_test set answer_desc = ? where id = ? ");
			String sql = "select id,right_item from genus_test";
			ResultSet set = statement.executeQuery(sql);
			while(set.next()){
				int id = set.getInt("id");
				String right_item = set.getString("right_item");
				System.out.println(id);
				System.out.println(right_item);
				if(right_item != null){
					Statement statement1 = connection.createStatement();
					sql = "select analysis from genus_test_answer where test_id = " + id + " and item = '" + right_item + "'";
					ResultSet rs = statement1.executeQuery(sql);
					String analysis = null;
					if(rs.next()){
						analysis = rs.getString("analysis");
					}
					if(analysis != null){
						//sql = "update genus_test set answer_desc = '" + analysis + "' where id = " + id;
						preparedStatement.setString(1, analysis);
						preparedStatement.setInt(2, id);
						int i = preparedStatement.executeUpdate();
						System.out.println("update " + i + " record.");
					}
				}
			}
		}catch(Exception e){
			e.printStackTrace();
		}
		
	}

}
